package com.heima.behavior.listener;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.service.ApFollowBehaviorService;
import com.heima.common.constants.FollowBehaviorConstants;
import com.heima.model.behavior.dtos.FollowBehaviorDto;
import com.xxl.job.core.biz.model.ReturnT;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class FollowBehaviorListener {

    @Autowired
    ApFollowBehaviorService apFollowBehaviorService;

    @KafkaListener(topics = FollowBehaviorConstants.FOLLOW_BEHAVIOR_TOPIC)
    public void followBehaviorListener(ConsumerRecord<?, ?> record) {
        Object value = record.value();
        FollowBehaviorDto dto = JSON.parseObject(value.toString(), FollowBehaviorDto.class);
        apFollowBehaviorService.saveFollowBehavior(dto);
    }

}
